package ${packageName}.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import ${basePackageName}service.${className}Service;
import ${basePackageName}mapper.${className}Mapper;
import org.springframework.stereotype.Service;
import ${basePackageName}entity.${className};

import org.springframework.beans.BeanUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import ${basePackageName}entity.bean.${className}Req;
import ${basePackageName}entity.bean.${className}Qo;
import ${basePackageName}util.XwUtil;
import org.apache.commons.lang3.StringUtils;

import ${basePackageName}entity.base.BoPage;
import ${basePackageName}entity.base.HeadDataPage;

import javax.annotation.Resource;

/**
 * @author： xw ftl auto
 * @create： ${.now?string("yyyy-MM-dd HH:mm:ss")}
 */
@Service
public class ${className}ServiceImpl extends ServiceImpl<${className}Mapper, ${className}> implements ${className}Service {

    @Resource
    private ${className}Mapper ${className?uncap_first}Mapper;

    @Override
    public BoPage<${className}> pageSample${className}(Integer pageNumber, Integer pageSize) {

        HeadDataPage headDataPage = new HeadDataPage();
        headDataPage.setPageNumber(pageNumber);
        headDataPage.setPageSize(pageSize);

        return boPageBean(new QueryWrapper<>(), headDataPage);
    }

    @Override
    public BoPage<${className}> pageEq${className}Dto(${className}Req ${className?uncap_first}Req) {

        ${className} query${className} = new ${className}();
        BeanUtils.copyProperties(${className?uncap_first}Req, query${className});

        LambdaQueryWrapper<${className}> queryWrapper = new LambdaQueryWrapper<>();

        <#list fields as field>
        <#if field.name == "id">
        queryWrapper.eq(null != ${className?uncap_first}Req.get${className}${field.name?cap_first}(),${className}::get${field.name?cap_first}, ${className?uncap_first}Req.get${className}${field.name?cap_first}());
        <#else >
        queryWrapper.eq(null != ${className?uncap_first}Req.get${field.name?cap_first}(),${className}::get${field.name?cap_first}, ${className?uncap_first}Req.get${field.name?cap_first}());
        </#if>
        </#list>

        if (StringUtils.isNotEmpty(${className?uncap_first}Req.getStartTime())) {
            Integer startTime = XwUtil.parseToInteger(${className?uncap_first}Req.getStartTime());
            queryWrapper.ge(${className}::get${fieldTime?cap_first}, startTime);
        }
        if (StringUtils.isNotEmpty(${className?uncap_first}Req.getEndTime())) {
            Integer endTime = XwUtil.parseToInteger(${className?uncap_first}Req.getEndTime());
            queryWrapper.le(${className}::get${fieldTime?cap_first}, endTime);
        }

        queryWrapper.orderByDesc(${className}::get${fieldOrderBy?cap_first});

        return boPageBean(queryWrapper, ${className?uncap_first}Req);
    }


    @Override
    public BoPage<${className}> page${className}Mapper(${className}Req ${className?uncap_first}Req) {
        if (!"desc".equals(${className?uncap_first}Req.getOrderValue()) && !"aes".equals(${className?uncap_first}Req.getOrderValue())) {
            ${className?uncap_first}Req.setOrderValue("desc");
        }

        ${className}Qo ${className?uncap_first}Qo = new ${className}Qo();
        BeanUtils.copyProperties(${className?uncap_first}Req,${className?uncap_first}Qo);

        if (${className?uncap_first}Req.get${className}Id() != null){
            ${className?uncap_first}Qo.setId(${className?uncap_first}Req.get${className}Id());
        }

        if (StringUtils.isNotEmpty(${className?uncap_first}Req.getStartTime())) {
            Integer startTime = XwUtil.parseToInteger(${className?uncap_first}Req.getStartTime());
            ${className?uncap_first}Qo.setStartTime(startTime);
        }
        if (StringUtils.isNotEmpty(${className?uncap_first}Req.getEndTime())) {
            Integer endTime = XwUtil.parseToInteger(${className?uncap_first}Req.getEndTime());
            ${className?uncap_first}Qo.setEndTime(endTime);
        }

        return boPageBeanBack(new QueryWrapper<>(), ${className?uncap_first}Req, wrapper -> ${className?uncap_first}Mapper.page${className}Mapper(${className?uncap_first}Qo));
    }


}
